import { throttledWatch } from "@vueuse/core";
import { chunk } from "lodash-es";
import { loadModule } from "./loadModule";

const exports = await loadModule("../../package/wasm/build/blendColor.wasm");
const { blendColors, __pin, __getArray, Uint32Array_ID, __newArray, __unpin } =
    exports;

/** 混合多个历史颜色,输入已经经过位置去重 */
export const AsBlendColors = (changeArray: number[][]) => {
    // console.time("flat");
    const input = changeArray.flat();
    // console.timeEnd("flat");
    // console.log(input.length);
    // console.time("blend");
    const singleSize = 5000;
    const col = chunk(input, singleSize).flatMap((i) => {
        let arrayPtr = __pin(__newArray(Uint32Array_ID as number, i));
        const result = (blendColors as any)(arrayPtr);
        const data = __getArray(result).map((i) => __getArray(i));
        __unpin(arrayPtr);
        return data;
    });

    // console.timeEnd("blend");
    return col;
};
